package guda.house.biz.form.village;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import guda.house.biz.util.FloatUtil;
import guda.house.dal.dataobject.SuiteDO;
import org.springframework.util.StringUtils;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;


public class SuiteForm {

    @NotNull(message = "不能为空")
    private Long unitId;
    @NotNull(message = "不能为空")
    @Size(min=1,max=10,message = "长度在0到10个字符之间")
    private String suiteName;
    @NotNull(message = "不能为空")
    @Pattern(regexp = "^([1-9]\\d*|0)(\\.\\d{1,3})?$",message = "最多2位数的小数")
    private String suiteArea;
    @Size(min=0,max=30,message = "长度在0到30个字符之间")
    private String cardOwner;
    @Size(min=0,max=30,message = "长度在0到30个字符之间")
    private String useType;
    @Size(min=0,max=30,message = "长度在0到30个字符之间")
    private String typeWater;
    @Size(min=0,max=30,message = "长度在0到30个字符之间")
    private String cardWater;
    @Size(min=0,max=10,message = "长度在0到10个字符之间")
    private String typeElectrical;
    @Size(min=0,max=10,message = "长度在0到10个字符之间")
    private String cardElectrical;
    @Size(min=0,max=150,message = "长度在0到150个字符之间")
    private String suiteComment;
    @NotNull(message = "不能为空")
    private String gmtDelivery;
    private String gmtCheckin;
    private Integer isDecoration;
    private Integer isCheckin;

    private Long villageId;
    private Long buildingId;

    private Long officeVarId;
    private Long employeeId;
    private Long buildingTypeId;



    public SuiteDO toDO(){
       SuiteDO suiteDO  = new SuiteDO();
        suiteDO.setUnitId(unitId);
        suiteDO.setCardElectrical(cardElectrical);
        suiteDO.setCardOwner(cardOwner);
        suiteDO.setIsCheckin(isCheckin);
        suiteDO.setIsDecoration(isDecoration);
        suiteDO.setSuiteComment(suiteComment);
        suiteDO.setTypeWater(typeWater);
        suiteDO.setUseType(useType);
        suiteDO.setSuiteName(suiteName);
        suiteDO.setCardWater(cardWater);
        suiteDO.setTypeWater(typeWater);
        suiteDO.setTypeElectrical(typeElectrical);
        suiteDO.setSuiteArea(FloatUtil.convert2gram(suiteArea));
        suiteDO.setOfficeVarId(officeVarId);
        suiteDO.setEmployeeId(employeeId);
        suiteDO.setBuildingTypeId(buildingTypeId);
        if(StringUtils.hasText(gmtDelivery)){
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date parse = simpleDateFormat.parse(gmtDelivery);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(parse);
                calendar.set(Calendar.HOUR_OF_DAY, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND,0);
                calendar.set(Calendar.MILLISECOND,0);
                suiteDO.setGmtDelivery(calendar.getTime());
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }

        }
        if(StringUtils.hasText(gmtCheckin)){
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date parse = simpleDateFormat.parse(gmtCheckin);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(parse);
                calendar.set(Calendar.HOUR_OF_DAY, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND,0);
                calendar.set(Calendar.MILLISECOND,0);
                suiteDO.setGmtCheckin(calendar.getTime());
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }

        }
       return suiteDO;
    }

    public Long getBuildingTypeId() {
        return buildingTypeId;
    }

    public void setBuildingTypeId(Long buildingTypeId) {
        this.buildingTypeId = buildingTypeId;
    }

    public Long getOfficeVarId() {
        return officeVarId;
    }

    public void setOfficeVarId(Long officeVarId) {
        this.officeVarId = officeVarId;
    }

    public Long getEmployeeId() {
        return employeeId;
    }

    public void setEmployeeId(Long employeeId) {
        this.employeeId = employeeId;
    }


    public Long getUnitId() {
        return unitId;
    }

    public void setUnitId(Long unitId) {
        this.unitId = unitId;
    }

    public String getSuiteName() {
        return suiteName;
    }

    public void setSuiteName(String suiteName) {
        this.suiteName = suiteName;
    }

    public String getSuiteArea() {
        return suiteArea;
    }

    public void setSuiteArea(String suiteArea) {
        this.suiteArea = suiteArea;
    }

    public String getCardOwner() {
        return cardOwner;
    }

    public void setCardOwner(String cardOwner) {
        this.cardOwner = cardOwner;
    }

    public String getUseType() {
        return useType;
    }

    public void setUseType(String useType) {
        this.useType = useType;
    }

    public String getTypeWater() {
        return typeWater;
    }

    public void setTypeWater(String typeWater) {
        this.typeWater = typeWater;
    }

    public String getCardWater() {
        return cardWater;
    }

    public void setCardWater(String cardWater) {
        this.cardWater = cardWater;
    }

    public String getTypeElectrical() {
        return typeElectrical;
    }

    public void setTypeElectrical(String typeElectrical) {
        this.typeElectrical = typeElectrical;
    }

    public String getCardElectrical() {
        return cardElectrical;
    }

    public void setCardElectrical(String cardElectrical) {
        this.cardElectrical = cardElectrical;
    }

    public String getSuiteComment() {
        return suiteComment;
    }

    public void setSuiteComment(String suiteComment) {
        this.suiteComment = suiteComment;
    }

    public String getGmtDelivery() {
        return gmtDelivery;
    }

    public void setGmtDelivery(String gmtDelivery) {
        this.gmtDelivery = gmtDelivery;
    }

    public String getGmtCheckin() {
        return gmtCheckin;
    }

    public void setGmtCheckin(String gmtCheckin) {
        this.gmtCheckin = gmtCheckin;
    }

    public Integer getIsDecoration() {
        return isDecoration;
    }

    public void setIsDecoration(Integer isDecoration) {
        this.isDecoration = isDecoration;
    }

    public Integer getIsCheckin() {
        return isCheckin;
    }

    public void setIsCheckin(Integer isCheckin) {
        this.isCheckin = isCheckin;
    }

    public Long getVillageId() {
        return villageId;
    }

    public void setVillageId(Long villageId) {
        this.villageId = villageId;
    }

    public Long getBuildingId() {
        return buildingId;
    }

    public void setBuildingId(Long buildingId) {
        this.buildingId = buildingId;
    }
}
